Skip to content

feat:Adds new Param in getChatMessages for better context handling #4273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 28, 2025

Conversation

whysosaket
Copy link
Contributor

This is a proposal to introduce a new parameter in the getChatMessages function that allows us to retrieve the latest user message, enabling more accurate memory retrieval. Currently, Mem0 Memory uses get_all to fetch all user memories, but this change would allow us to perform a semantic search, which is more efficient for handling context.

I'd like to understand if there's a better approach to achieve this, and whether it makes sense to apply the same logic to other components as well. Thanks!

Changelog

  • Enhanced getChatMessages Method: Introduced a new parameter currentMessages to allow for dynamic message retrieval based on the latest user input, improving the context handling during chat sessions.
  • Improved Message Handling: Updated logic to prepend messages from currentMessages to the chat history, ensuring that the latest user input is considered when fetching the memories.

@whysosaket
Copy link
Contributor Author

Hi @chungyau97,
Could you please review this and confirm that this method works or is there a better way to handle this use-case?

@whysosaket
Copy link
Contributor Author

Hey @chungyau97,
Can you please help here?

@whysosaket
Copy link
Contributor Author

Hey @HenryHengZJ , can you help here?

@HenryHengZJ
Copy link
Contributor

hey sorry for late reply. I think a better approach is to use getSessionChatHistory and pass in the incomingInput. Then in the getSessionChatHistory function, pass the incomingInput to const initializedInstance: FlowiseMemory = await newNodeInstance.init(memoryNode.data, incomingInput, {

Finally, in the mem0 you can then take the input from init function async init(nodeData: INodeData, input: string, options: ICommonObject): Promise<any> {

@whysosaket
Copy link
Contributor Author

hey sorry for late reply. I think a better approach is to use getSessionChatHistory and pass in the incomingInput. Then in the getSessionChatHistory function, pass the incomingInput to const initializedInstance: FlowiseMemory = await newNodeInstance.init(memoryNode.data, incomingInput, {

Finally, in the mem0 you can then take the input from init function async init(nodeData: INodeData, input: string, options: ICommonObject): Promise<any> {

This really helped a lot, was just a few lines of change, super thanks!!

image

@whysosaket whysosaket marked this pull request as ready for review May 12, 2025 10:02
@whysosaket whysosaket mentioned this pull request May 12, 2025
@alvobot
Copy link

alvobot commented May 13, 2025

Is it possible to add a self-hosting feature?

Copy link
Contributor

@HenryHengZJ HenryHengZJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@HenryHengZJ HenryHengZJ merged commit 9682a0c into FlowiseAI:main May 28, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants